﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Mimoza.AgentLayer
{
    public class SystemPower
    {
        public static void Reboot()
        {
#if WindowsCE
            SetSystemPowerState(null, POWER_STATE_RESET, 0);
            //ExitWindowsEx(EWX_REBOOT, 0);
#endif
        }

/*        public static void PowerOff()
        {
#if WindowsCE
            ExitWindowsEx(EWX_REBOOT, 0);
#endif
        }
 */ 
        const int POWER_STATE_RESET =   0x800000;
        const int POWER_STATE_OFF =     0x200000;
        [System.Runtime.InteropServices.DllImport("coredll.dll")]
        private static extern Int32 SetSystemPowerState(System.Char[] psState, System.Int32 StateFlags,
            System.Int32 Options);

        [DllImport("aygshell.dll")]
        private static extern bool ExitWindowsEx(uint uFlags, int dwReserved);

        //[DllImport("aygshell.dll", SetLastError = true)]
        //private static extern int ExitWindowsEx([MarshalAs(UnmanagedType.U4)] ExitWindowsAction uFlags, [MarshalAs(UnmanagedType.U4)] uint dwReserved);

        const uint EWX_REBOOT = 0x00000002;
        const uint EWX_POWEROFF = 0x00000008;
    }
}
